//
// Created by 15548 on 2025/2/17.
//

#ifndef A_STAR_H
#define A_STAR_H


#include <Arduino.h>
#include <vector>
#include <queue>
#include <algorithm>

// Define grid size
const int GRID_SIZE = 19;

// Define directions
extern std::vector<std::pair<int, int>> cardinal_directions;
extern std::vector<std::pair<int, int>> all_directions;
extern std::vector<std::pair<int, int>> forbidden_coords;
extern std::vector<std::pair<int, int>> low_priority_coords;

// Function to initialize the grid based on a smaller 10x10 grid
void initializeGrid(char grid[GRID_SIZE][GRID_SIZE], char grid_10x10[10][10]);

// Function to check for obstacles nearby
bool hasObstacleNearby(int x, int y, char grid[GRID_SIZE][GRID_SIZE]);

// Heuristic function for A* algorithm
int heuristic(const std::pair<int, int>& a, const std::pair<int, int>& b);

// 管理低优先级坐标的函数
void addLowPriorityCoord(int x, int y);
void addLowPriorityCoords(const std::vector<std::pair<int, int>>& coords);
void clearLowPriorityCoords();

// A* algorithm to find the path
std::vector<std::pair<int, int>> aStar(char grid[GRID_SIZE][GRID_SIZE], const std::pair<int, int>& start, const std::pair<int, int>& end);

#endif

